package com.yulan.fastkillcourse.mq;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MQConfig {
    //一号秒杀通道
    public static final String FASTKILL_QUEUE1= "fastkill.queue1";
    //二号秒杀通道
    public static final String FASTKILL_QUEUE2= "fastkill.queue2";

    public static final String TOPIC_EXCHANGE = "topicExchange";

    public static final String TOPIC_ROUTE_KEY1 = "fastkill.key1";

    public static final String TOPIC_ROUTE_KEY2 = "fastkill.key2";

    @Bean
    public MessageConverter getMessageConverter() {
        return new Jackson2JsonMessageConverter();
    }



    @Bean
    public Queue fastkill_queue1() { return new Queue(FASTKILL_QUEUE1, true); }

    @Bean
    public Queue fastkill_queue2() { return new Queue(FASTKILL_QUEUE2, true); }


    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange(TOPIC_EXCHANGE);
    }

    @Bean
    public Binding topicBinding1(){
        return BindingBuilder.bind(fastkill_queue1()).to(topicExchange()).with(TOPIC_ROUTE_KEY1);
    }

    @Bean
    public Binding topicBinding2(){
        return BindingBuilder.bind(fastkill_queue2()).to(topicExchange()).with(TOPIC_ROUTE_KEY2);
    }


}
